<h1>E-mail</h1>

<% if !@dirty %>
<p>Changes will become active after pressing the 'Activate changes' button below.</p>
<% end %>
<% if @dirty %>
<p>Changes not yet activated. Press the 'Activate changes' button below to activate.</p>
<% end %>

<% form_tag do %>
<h2>Users</h2>
<table class="index" cellpadding="0" cellspacing="0" border="0">
  <thead>
    <tr>
      <th>User name</th>
      <th>E-mail address (comma separated)</th>
      <% @groups.each do |group| %>
        <th><%= group %></th>
      <% end %>
      <th>Action</th>
      <th width="100%"></th>
    </tr>
  </thead>
  <tbody>
  <% @virtual_addresses.each do |vaddr| %>
    <tr>
      <td><%= vaddr.user %></td>
      <td>
          <%= text_field_tag "vaddr[#{ vaddr.user }][redirect]", vaddr.redirect, :size => 50 %>
          <%= errors_for(vaddr, :redirect) %>
      </td>
      <% @groups.each do |group| %>
        <td>
          <%= check_box_tag "vaddr[#{ vaddr.user }][member_of_groups][#{ group }]", {}, vaddr.member_of?(group) %>
        </td>
      <% end %>
      <td>
        <%= submit_tag "remove[#{ vaddr.user }]", :name => "remove[#{ vaddr.user }]", :value => "Remove #{ vaddr.user }" %>
      </td>
    </tr>
  <% end %>
    <tr>
      <td><%= text_field_tag "new_vaddr[user]", "", :size => 20 %></td>
      <td><%= text_field_tag "new_vaddr[redirect]", "", :size => 50 %></td>
      <% @groups.each do |group| %>
        <td>
          <%= check_box_tag "new_vaddr[member_of_groups][#{ group }]", {}, group == "all" %>
        </td>
      <% end %>
      <td>
        <%= submit_tag "add", :name => "add", :value => "Add" %>
      </td>
    </tr>
  </tbody>
</table>
<h2>Groups and aliases</h2>
<table class="index" cellpadding="0" cellspacing="0" border="0">
  <thead>
    <tr>
      <th>Group/alias name</th>
      <th>Action</th>
      <th width="100%"></th>
    </tr>
  </thead>
  <tbody>
  <% (@groups - ["all"]).each do |group| %>
    <tr>
      <td><%= group %></th>
      <td>
        <%= submit_tag "g_remove[#{ group }]", :name => "g_remove[#{ group }]", :value => "Remove #{ group }" %>
      </td>
    </tr>
  <% end %>
  <tr>
    <td><%= text_field_tag "new_group", "", :size => 20 %></td>
    <td><%= submit_tag "g_add", :name => "add", :value => "Add" %></td>
  </tr>
  </tbody>
</table>
<p>
  <%= submit_tag "reset", :name => "reset", :value => "Undo all changes!", :onclick => "return confirm('All your changes will be lost. Continue?');" %>
  <%= submit_tag "activate", :name => "activate", :value => "Activate changes" %>
</p>
<% end %>
